package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MCourse;
import com.ruoyi.system.service.IMCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程套餐Controller
 * 
 * @author ruoyi
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/system/course")
public class MCourseController extends BaseController
{
    @Autowired
    private IMCourseService mCourseService;

    /**
     * 查询课程套餐列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MCourse mCourse)
    {
        startPage();
        List<MCourse> list = mCourseService.selectMCourseList(mCourse);
        return getDataTable(list);
    }



    /**
     * 导出课程套餐列表
     */
    @PreAuthorize("@ss.hasPermi('system:course:export')")
    @Log(title = "课程套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MCourse mCourse)
    {
        List<MCourse> list = mCourseService.selectMCourseList(mCourse);
        ExcelUtil<MCourse> util = new ExcelUtil<MCourse>(MCourse.class);
        util.exportExcel(response, list, "课程套餐数据");
    }

    /**
     * 获取课程套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:course:query')")
    @GetMapping(value = "/{courseid}")
    public AjaxResult getInfo(@PathVariable("courseid") Long courseid)
    {
        return AjaxResult.success(mCourseService.selectMCourseByCourseid(courseid));
    }

    /**
     * 新增课程套餐
     */
    @PreAuthorize("@ss.hasPermi('system:course:add')")
    @Log(title = "课程套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MCourse mCourse)
    {
        return toAjax(mCourseService.insertMCourse(mCourse));
    }

    /**
     * 修改课程套餐
     */
    @PreAuthorize("@ss.hasPermi('system:course:edit')")
    @Log(title = "课程套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MCourse mCourse)
    {
        return toAjax(mCourseService.updateMCourse(mCourse));
    }

    /**
     * 删除课程套餐
     */
    @PreAuthorize("@ss.hasPermi('system:course:remove')")
    @Log(title = "课程套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseids}")
    public AjaxResult remove(@PathVariable Long[] courseids)
    {
        return toAjax(mCourseService.deleteMCourseByCourseids(courseids));
    }
}
